home *** CD-ROM | disk | FTP | other *** search
/ Sprite 1984 - 1993 / Sprite 1984 - 1993.iso / src / machserver / 1.098 / dbg / sun3.md / dbgRs232.c.not.used < prev    next >
Text File  |  1989-06-12  |  5KB  |  226 lines

  1. /* dbgRs232.c -
  2.  *
  3.  *     This file contains routines that read, write, and initialize the
  4.  *     Zilog RS232 chip.
  5.  *
  6.  * Copyright 1985 Regents of the University of California
  7.  * All rights reserved.
  8.  */
  9.  
  10. #ifndef lint
  11. static char rcsid[] = "$Header: /sprite/src/kernel/dbg/sun3.md/RCS/dbgRs232.c,v 8.2 89/06/12 11:13:02 rab Exp $ SPRITE (Berkeley)";
  12. #endif not lint
  13.  
  14. #include "sprite.h"
  15. #include "dev.h"
  16. #include "devAddrs.h"
  17. #include "dbg.h"
  18. #include "dbgRs232.h"
  19. #include "dbgInt.h"
  20. #include "sys.h"
  21. #include "mach.h"
  22.  
  23. /*
  24.  * Channel A is setup to be the debuggers channel.  It gets configured
  25.  * to be a polling device, so we avoid configuring the other channel
  26.  * in the same way.  That would screw up any attached terminals.
  27.  */
  28. #define USE_CHAN_A
  29.  
  30. /*
  31.  * Struct to access channel A control register
  32.  */
  33. static volatile Dev_ZilogDevice *zilogAddrA;
  34.  
  35. /*
  36.  * Struct to access channel B control register
  37.  */
  38. static Dev_ZilogDevice *zilogAddrB;
  39.  
  40.  
  41. /*
  42.  * ----------------------------------------------------------------------------
  43.  *
  44.  * DbgRs232Init --
  45.  *
  46.  *    Initialize the Zilog chip.
  47.  *
  48.  *    Currently, only channel A is used. Channel B is not initialized
  49.  *    because it is used a serial port.
  50.  *
  51.  * Results:
  52.  *    None.
  53.  *
  54.  * Side effects:
  55.  *    The two global zilog addresses for the two channels are initialized.
  56.  *
  57.  * ----------------------------------------------------------------------------
  58.  */
  59.  
  60. void
  61. DbgRs232Init()
  62. {
  63. #ifdef USE_CHAN_A
  64.     zilogAddrA = (Dev_ZilogDevice *) (DEV_ZILOG_SERIAL_ADDR | 4);
  65. #endif USE_CHAN_A
  66.  
  67. #ifdef USE_CHAN_B
  68.     zilogAddrB = (volatile Dev_ZilogDevice *) DEV_ZILOG_SERIAL_ADDR;
  69. #endif USE_CHAN_B
  70.  
  71.     /*
  72.      * Reset the channel.
  73.      */
  74.  
  75. #ifdef USE_CHAN_A
  76.     Dev_ZilogWriteReg(zilogAddrA, 9, WRITE9_RESET_CHAN_A); 
  77.     MACH_DELAY(10);
  78. #endif USE_CHAN_A
  79.  
  80. #ifdef USE_CHAN_B
  81.     Dev_ZilogWriteReg(zilogAddrB, 9, WRITE9_RESET_WORLD); 
  82.     MACH_DELAY(10);
  83. #endif USE_CHAN_B
  84.  
  85.     /*
  86.      * Initialize channel A.
  87.      */
  88.  
  89. #ifdef USE_CHAN_A
  90.     Dev_ZilogInit(zilogAddrA, DEV_ZILOG_SERIAL_SPEED);
  91. #endif USE_CHAN_A
  92.  
  93.     /*
  94.      * Initialize channel B.
  95.      */
  96.  
  97. #ifdef USE_CHAN_B
  98.     Dev_ZilogInit(zilogAddrB, DEV_ZILOG_SERIAL_SPEED);
  99. #endif USE_CHAN_B
  100. }
  101.  
  102.  
  103. /*
  104.  * ----------------------------------------------------------------------------
  105.  *
  106.  * DbgRs232ReadChar --
  107.  *
  108.  *     Return the next character that is available on the given channel.  If
  109.  *     no character available then busy wait.
  110.  *
  111.  * Results:
  112.  *     The next available character.
  113.  *
  114.  * Side effects:
  115.  *     None.
  116.  *
  117.  * ----------------------------------------------------------------------------
  118.  */
  119. char
  120. DbgRs232ReadChar(channel)
  121.     Dbg_Rs232Channel    channel;    /* Channel to read from */
  122. {
  123.     int reg;
  124.  
  125.     /*
  126.      * Busy wait until a character is ready.
  127.      */
  128.  
  129.     while(1) {
  130.     if (channel == DBG_RS232_CHANNELA) {
  131. #ifdef USE_CHAN_A
  132.         reg = Dev_ZilogReadReg(zilogAddrA, 0); 
  133. #else
  134.         printf("DbgRs232ReadChar called on channel A.\n");
  135.         return(0);
  136. #endif USE_CHAN_A
  137.     } else {
  138. #ifdef USE_CHAN_B
  139.         reg = Dev_ZilogReadReg(zilogAddrB, 0); 
  140. #else
  141.         printf("DbgRs232ReadChar called on channel B.\n");
  142.         return(0);
  143. #endif USE_CHAN_B
  144.     }
  145.     if (reg & READ0_RX_READY) {
  146.         break;
  147.     }
  148.     DbgCheckNmis();
  149.     }
  150.  
  151.     /*
  152.      * Read the character.
  153.      */
  154.  
  155.     if (channel == DBG_RS232_CHANNELA) {
  156.     return(Dev_ZilogReadReg(zilogAddrA, 8));
  157.     } else {
  158.     return(Dev_ZilogReadReg(zilogAddrB, 8));
  159.     }
  160. }
  161.  
  162.  
  163. /*
  164.  * ----------------------------------------------------------------------------
  165.  *
  166.  * DbgRs232WriteChar --
  167.  *
  168.  *     Write a character to the given channel.  Will busy wait until the 
  169.  *     transmit buffer is empty.
  170.  *
  171.  * Results:
  172.  *     None.
  173.  *
  174.  * Side effects:
  175.  *     None.
  176.  *
  177.  * ----------------------------------------------------------------------------
  178.  */
  179.  
  180. void
  181. DbgRs232WriteChar(channel, value)
  182.     Dbg_Rs232Channel channel;    /* Channel to write to */
  183.     char          value;    /* Value to write */
  184. {
  185.     int    reg;
  186.  
  187.     /*
  188.      * Busy wait until the transmit buffer is empty.
  189.      */
  190.  
  191.     while (1) {
  192.     if (channel == DBG_RS232_CHANNELA) {
  193. #ifdef USE_CHAN_A
  194.         reg = Dev_ZilogReadReg(zilogAddrA, 0);
  195. #else
  196.         printf("DbgRs232WriteChar called on channel A.\n");
  197.         return;
  198. #endif USE_CHAN_A
  199.     } else {
  200. #ifdef USE_CHAN_B
  201.         reg = Dev_ZilogReadReg(zilogAddrB, 0);
  202. #else
  203.         printf("DbgRs232WriteChar called on channel B.\n");
  204.         return;
  205. #endif USE_CHAN_B
  206.     }
  207.     if (reg & READ0_TX_READY) {
  208.         break;
  209.     }
  210.     }
  211.  
  212.     /*
  213.      * Write the character
  214.      */
  215.  
  216.     if (channel == DBG_RS232_CHANNELA) {
  217. #ifdef USE_CHAN_A
  218.     Dev_ZilogWriteReg(zilogAddrA, 8, (int) value);
  219. #endif USE_CHAN_A
  220.     } else {
  221. #ifdef USE_CHAN_B
  222.     Dev_ZilogWriteReg(zilogAddrB, 8, (int) value);
  223. #endif USE_CHAN_B
  224.     }
  225. }
  226.